<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="ABC分类" prop="abcClass"
                :rules="[
                 ]">
              <el-input v-model="inputForm.abcClass" placeholder="请填写ABC分类"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="领料用途" prop="accoCodeName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.accoCodeName" placeholder="请填写领料用途"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="抛帐会计科目（借方）" prop="acctCodeName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.acctCodeName" placeholder="请填写抛帐会计科目（借方）"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="金额" prop="amt"
                :rules="[
                 ]">
              <el-input v-model="inputForm.amt" placeholder="请填写金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="发科仓库" prop="assignLocNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.assignLocNo" placeholder="请填写发科仓库"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="审核人" prop="audEmpName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.audEmpName" placeholder="请填写审核人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="受益成本中心" prop="benifitCostCen"
                :rules="[
                 ]">
              <el-input v-model="inputForm.benifitCostCen" placeholder="请填写受益成本中心"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="关联方公司id" prop="bsCompId"
                :rules="[
                 ]">
              <el-input v-model="inputForm.bsCompId" placeholder="请填写关联方公司id"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="采购员" prop="buyer"
                :rules="[
                 ]">
              <el-input v-model="inputForm.buyer" placeholder="请填写采购员"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="物资名称" prop="chnName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.chnName" placeholder="请填写物资名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="规格型号" prop="chnSpec"
                :rules="[
                 ]">
              <el-input v-model="inputForm.chnSpec" placeholder="请填写规格型号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程合同" prop="civiConNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.civiConNo" placeholder="请填写工程合同"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程项目编号" prop="civiNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.civiNo" placeholder="请填写工程项目编号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="物资分类第一级" prop="className"
                :rules="[
                 ]">
              <el-input v-model="inputForm.className" placeholder="请填写物资分类第一级"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="施工单位" prop="conDept"
                :rules="[
                 ]">
              <el-input v-model="inputForm.conDept" placeholder="请填写施工单位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="成本中心" prop="costCenter"
                :rules="[
                 ]">
              <el-input v-model="inputForm.costCenter" placeholder="请填写成本中心"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="保管员" prop="deliver"
                :rules="[
                 ]">
              <el-input v-model="inputForm.deliver" placeholder="请填写保管员"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="出库日期" prop="finalDate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.finalDate" placeholder="请填写出库日期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="是否直发现场" prop="isZhiFa"
                :rules="[
                 ]">
              <el-input v-model="inputForm.isZhiFa" placeholder="请填写是否直发现场"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="申请日期" prop="issueDate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.issueDate" placeholder="请填写申请日期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="领料单号" prop="issueTallyNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.issueTallyNo" placeholder="请填写领料单号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="领料部门" prop="issueTranDeptNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.issueTranDeptNo" placeholder="请填写领料部门"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="领料人" prop="issueTranEmpName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.issueTranEmpName" placeholder="请填写领料人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="领料类别" prop="issuetype"
                :rules="[
                 ]">
              <el-input v-model="inputForm.issuetype" placeholder="请填写领料类别"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="物资类别第四级" prop="itemName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.itemName" placeholder="请填写物资类别第四级"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="物资类别第三级" prop="kundAName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.kundAName" placeholder="请填写物资类别第三级"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="物资类别第二级" prop="kinName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.kinName" placeholder="请填写物资类别第二级"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="仓位" prop="locDes"
                :rules="[
                 ]">
              <el-input v-model="inputForm.locDes" placeholder="请填写仓位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="品级" prop="matrlGrade"
                :rules="[
                 ]">
              <el-input v-model="inputForm.matrlGrade" placeholder="请填写品级"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="物料编码" prop="matrlNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.matrlNo" placeholder="请填写物料编码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="单据id" prop="mm024ID"
                :rules="[
                 ]">
              <el-input v-model="inputForm.mm024ID" placeholder="请填写单据id"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="旧编码" prop="oldMatrlno"
                :rules="[
                 ]">
              <el-input v-model="inputForm.oldMatrlno" placeholder="请填写旧编码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="年修项目编号" prop="overhaulNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.overhaulNo" placeholder="请填写年修项目编号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="计划用途" prop="planUseCode"
                :rules="[
                 ]">
              <el-input v-model="inputForm.planUseCode" placeholder="请填写计划用途"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="领料属性" prop="property"
                :rules="[
                 ]">
              <el-input v-model="inputForm.property" placeholder="请填写领料属性"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="数量" prop="qty"
                :rules="[
                 ]">
              <el-input v-model="inputForm.qty" placeholder="请填写数量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="研发项目编号" prop="rdNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.rdNo" placeholder="请填写研发项目编号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="领料人" prop="receiver"
                :rules="[
                 ]">
              <el-input v-model="inputForm.receiver" placeholder="请填写领料人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注" prop="remark"
                :rules="[
                 ]">
              <el-input v-model="inputForm.remark" placeholder="请填写备注"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="关联入库单号" prop="rissueTallyNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.rissueTallyNo" placeholder="请填写关联入库单号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="关联退库单号" prop="tissueTallyNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.tissueTallyNo" placeholder="请填写关联退库单号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="计量单位" prop="unit"
                :rules="[
                 ]">
              <el-input v-model="inputForm.unit" placeholder="请填写计量单位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="单价" prop="unitPrice"
                :rules="[
                 ]">
              <el-input v-model="inputForm.unitPrice" placeholder="请填写单价"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="凭证号" prop="vchrNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.vchrNo" placeholder="请填写凭证号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="购货单位" prop="venderId"
                :rules="[
                 ]">
              <el-input v-model="inputForm.venderId" placeholder="请填写购货单位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          abcClass: '',
          accoCodeName: '',
          acctCodeName: '',
          amt: '',
          assignLocNo: '',
          audEmpName: '',
          benifitCostCen: '',
          bsCompId: '',
          buyer: '',
          chnName: '',
          chnSpec: '',
          civiConNo: '',
          civiNo: '',
          className: '',
          conDept: '',
          costCenter: '',
          deliver: '',
          finalDate: '',
          isZhiFa: '',
          issueDate: '',
          issueTallyNo: '',
          issueTranDeptNo: '',
          issueTranEmpName: '',
          issuetype: '',
          itemName: '',
          kundAName: '',
          kinName: '',
          locDes: '',
          matrlGrade: '',
          matrlNo: '',
          mm024ID: '',
          oldMatrlno: '',
          overhaulNo: '',
          planUseCode: '',
          property: '',
          qty: '',
          rdNo: '',
          receiver: '',
          remark: '',
          rissueTallyNo: '',
          tissueTallyNo: '',
          unit: '',
          unitPrice: '',
          vchrNo: '',
          venderId: '',
          remarks: ''
        }
      }
    },
    components: {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建表单`
        } else if (method === 'edit') {
          this.title = '修改表单'
        } else if (method === 'view') {
          this.title = '查看表单'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/spareparts/material/sparepartsErpBank/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.sparepartsErpBank)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/spareparts/material/sparepartsErpBank/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>